import {expect} from "chai";
import { Mat2 } from "../src/Mat2";
describe("Mat2", function () {
    before(function() {
        console.log("开始自动化测试Mat2...");
    });

    after(function() {
        console.log("结束...");
    });
    beforeEach(function() {
    });

    afterEach(function() {
    });
    it('#constructor', function () {
        let mat2=new Mat2();
        expect(mat2.equal([1,0,0,1])).to.equal(true);
    });
    it('#clone', function () {
        let mat2=new Mat2();
        let mat2clone=mat2.clone();
        expect(mat2clone.equal(mat2)).to.equal(true);
    });
    it('#clone', function () {
        let mat2=new Mat2();
        let cope=new Mat2([0.5,1,0,1]);
        mat2.copy(cope);
        expect(mat2.equal(cope)).to.equal(true);
    });
    it('#equal', function () {
        let mat2=new Mat2();
        let cope=new Mat2([0.5,1,0,1]);
        mat2.copy(cope);
        expect(mat2.equal(cope)).to.equal(true);
    });
    it('#identity', function () {
        let mat2=new Mat2([0.5,1,0,1]);
        mat2.identity();
        expect(mat2.equal([1,0,0,1])).to.equal(true);
    });
    it('#transpose', function () {
        let mat2=new Mat2([0.5,1,0,1]);
        mat2.transpose();
        expect(mat2.equal([0.5,0,1,1])).to.equal(true);
    });
    it('#invert', function () {
        let mat2=new Mat2([0.5,1,0,1]);
        mat2.invert();
        expect(mat2.equal([2,-2,-0,1])).to.equal(true);
    });
    it('#adjoint', function () {
        let mat2=new Mat2([0.5,1,0,1]);
        mat2.adjoint();
        expect(mat2.equal([1,-1,-0,0.5])).to.equal(true);
    });
    it('#determinant', function () {
        let mat2=new Mat2([0.5,1,0,1]);
        let dete=mat2.determinant();
        expect(dete).to.equal(0.5);
    });
    it('#multiply', function () {
        let left=new Mat2([0.5,1,0,1]);
        let right=new Mat2([-0.5,-1,0,1]);
        left.multiply(right);        
        expect(left.equal([-0.25,-1.5,0,1])).to.equal(true);
    });
    it('#premultiply', function () {
        let left=new Mat2([0.5,1,0,1]);
        let right=new Mat2([-0.5,-1,0,1]);
        right.premultiply(left);        
        expect(right.equal([-0.25,-1.5,0,1])).to.equal(true);
    });
    it('#scale', function () {
        let left=new Mat2([0.5,1,0,1]);
        left.scale([1,2]);        
        expect(left.equal([0.5,1,0,2])).to.equal(true);
    });
    it('#rotate', function () {
        let left=new Mat2([0.5,1,0,1]);
        left.rotate(Math.PI/3);        
        expect(left.equal([0.25,1.366025447845459,-0.4330126941204071,-0.3660254180431366])).to.equal(true);
    });
    it('#fromRotation', function () {
        let left=new Mat2();
        left.fromRotation(Math.PI/3);        
        expect(left.equal([0.5,0.8660253882408142,-0.8660253882408142,0.5])).to.equal(true);
    });
    it('#fromScaling', function () {
        let left=new Mat2();
        left.fromScaling([0.4,0.5]);        
        expect(left.equal([0.4,0,0,0.5])).to.equal(true);
    });
    it('#toString', function () {
        let left=new Mat2();
        let a=left.toString();        
        expect(a).to.equal('Mat2(1,0,0,1)');
    });
})